package logic

import (
	"context"
	"hema-fresh/hemarpc/models/mysql"

	"hema-fresh/hemarpc/hemarpc"
	"hema-fresh/hemarpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ProductAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewProductAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ProductAddLogic {
	return &ProductAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 创建
func (l *ProductAddLogic) ProductAdd(in *hemarpc.ProductAddRequest) (*hemarpc.ProductAddResponse, error) {
	// todo: add your logic here and delete this line

	hema := mysql.HemaProduct{
		ProductName:  in.ProductName,
		ProductPrice: float64(in.ProductPrice),
		ProductStock: int(in.ProductStock),
		HemaTypeId:   int(in.HemaTypeId),
	}

	if err := hema.ProductAdd(mysql.DB); err != nil {
		return nil, err
	}

	return &hemarpc.ProductAddResponse{
		HemaProductId: int64(hema.ID),
	}, nil
}
